1 Abstract

A (very) short summary of the report. As an example, you can simply write one sentence for each section in the report.

2 Introduction

The scale of complexity a a human brain has over that of a mouse is well known among neuroscientists. The structure of a mouse brain is very similar in structure and function to a human brain, thus making them an interest of study in neurological testing. In this analysis, we look at data from a recent experiment by Steinmetz et al. (2019) which observed the activity of neurons in the visual cortex of mice when presented with stimuli. Following this, the mice were required to make a decision, using a wheel which was controlled by their forepaws. Their decision foretold whether they recieved an award or a penalty.

3 Background

The data set we will be using only looks at two of the ten mice in the study, Cori and Forssmann from mid-December 2016 to early November 2017. Both mice had varying number of trials, with 39 tracked times for each trial. Since these five sessions have varying amounts of trials, we look for a way to minimize the data from these five sessions into one long data set. To do this, we first must create an accurate response variable for our model, one that we can compare imbalanced trials between sessions. We choose to compare the mean firing rates for each trial in each session. This measure would be the average number of spikes per seconds across all neurons measuring within a 0.4 second interval. The choice of 0.4 seconds as our interval is by design of the experiment, which focused on spike trains of neurons from the presenting of the stimuli to 0.4 seconds after. The resulting data frame, from the five merged sessions, is shown below. We have a data set of 1196 trials, spanning across the 5 sessions, with the mean firing rate, the left and right contrasts, feedback type, and an ID column for which session the trial came from.

ses1 <- readRDS("./Data/session1.rds")
ses2 <- readRDS("./Data/session2.rds")
ses3 <- readRDS("./Data/session3.rds")
ses4 <- readRDS("./Data/session4.rds")
ses5 <- readRDS("./Data/session5.rds")


session=list()
for(i in 1:5){
  session[[i]]=readRDS(paste('./Data/session',i,'.rds',sep=''))
  #print(session[[i]]$mouse_name)
  #print(session[[i]]$date_exp)
}


# id=11
# session[[5]]$feedback_type[id]
# session[[5]]$contrast_left[id]
# session[[5]]$contrast_right[id]
# length(session[[1]]$time[[id]])
# dim(session[[5]]$spks[[id]])

#ID=1
t=0.4 # from Background 

# Rows of contrast is quantity of trials (varying)
# rows of spikes/times is quantity of neurons (varying)
# columns of spikes/times is tracked sessions of brain (fixed)
# 
# n.trials=length(session[[ID]]$spks)
# # Number of nuerons is the rows of spikes. which varies 
# n.neurons=dim(session[[ID]]$spks[[1]])[1]
# 
# # Obtain the firing rate 
# firingrate=numeric(n.trials)
# for(i in 1:n.trials){
#   firingrate[i]=sum(session[[ID]]$spks[[i]])/n.neurons/t
# }
# firingrate

firingrate <- c()
total.fire.rate <- sapply(1:5, function(i)
  sapply(1:length(session[[i]]$spks), function(j)
    firingrate = c(firingrate, sum(session[[i]]$spks[[j]]) / dim(session[[i]]$spks[[j]])[1] / t)))

# Flatten the list of lists
rates.flat <- (unlist(total.fire.rate))
mice <- data.frame("Firing.Rate" = rates.flat)

# Now create dataframe to join with session as a variable as well
contrast.dat <- data.frame()
abc <- sapply(1:5, function(i)
  cbind(
    session[[i]]$contrast_left,
    session[[i]]$contrast_right,
    session[[i]]$feedback_type,
    rep(i, length(session[[i]]$contrast_left))
  ))
contrast.dat <- do.call(rbind, abc)

# Merge data.frames
mice <- cbind(mice, contrast.dat)
colnames(mice) <-
  c("Firing.Rate", "C.Left", "C.Right", "Feedback_Type", "Session")

# Convert mice Session into factor
cols2fac <- c("C.Left", "C.Right", "Feedback_Type", "Session")
mice[cols2fac] <- lapply(mice[cols2fac], factor)
mice

4 Descriptive analysis

Select the variables you find relevant based on your understanding in the Background section. Summarize univariate descriptive statistics for the selected variables (mean, standard deviations, missing values, quantiles, etc.). You can create the table using functions in base R, or use packages (see, e.g., this note).

  • Choose the summary measure to be used. Your options are the mean, median, quantiles, etc. Be sure to justify your choice.
# Create Histograms, 
# separated by Session
ggplotly(ggplot(mice, aes(x = Firing.Rate, fill = Session)) + geom_histogram(bins = 22, alpha = 0.8))
# Separated by Feedback Type
ggplotly(ggplot(mice, aes(x = Firing.Rate, fill = Feedback_Type)) + geom_histogram(bins = 22, alpha = 0.8))
# Box Plots 
# For Left Contrast
ggplot(mice, aes(x = C.Left, y= Firing.Rate, fill = C.Left)) + geom_boxplot()

# Right Contrast
ggplot(mice, aes(x = C.Right, y= Firing.Rate, fill = C.Right)) + geom_boxplot()

5 Inferential analysis

6 Sensitivity analysis

7 Discussion

Conclude your analysis in this section. You can touch on the following topics.

  • A brief recap of this project.
  • Suggestions for future research and/or policy making given your findings.
  • Caveats of the current analysis.

8 Predictive Modeling

Acknowledgement

By default, it is assumed that you have discussed this project with your teammates and instructors. List any other people that you have discussed this project with.

Reference

List any references you cited in the report. See here for the APA format, as an example:

Imbens, G., & Rubin, D. (2015). Stratified Randomized Experiments. In Causal Inference for Statistics, Social, and Biomedical Sciences: An Introduction (pp. 187-218). Cambridge: Cambridge University Press. doi:10.1017/CBO9781139025751.010

Session info

Report information of your R session for reproducibility.

sessionInfo()
## R version 4.2.2 (2022-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 22621)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.utf8 
## [2] LC_CTYPE=English_United States.utf8   
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.utf8    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] plotly_4.10.0 ggplot2_3.4.0
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.1.2  xfun_0.31         bslib_0.3.1       purrr_0.3.4      
##  [5] colorspace_2.0-3  vctrs_0.5.0       generics_0.1.2    htmltools_0.5.2  
##  [9] viridisLite_0.4.0 yaml_2.3.5        utf8_1.2.2        rlang_1.0.6      
## [13] jquerylib_0.1.4   pillar_1.7.0      glue_1.6.2        withr_2.5.0      
## [17] DBI_1.1.2         lifecycle_1.0.3   stringr_1.4.0     munsell_0.5.0    
## [21] gtable_0.3.0      htmlwidgets_1.5.4 evaluate_0.15     labeling_0.4.2   
## [25] knitr_1.40        fastmap_1.1.0     crosstalk_1.2.0   fansi_1.0.3      
## [29] highr_0.9         scales_1.2.0      jsonlite_1.8.0    farver_2.1.0     
## [33] digest_0.6.29     stringi_1.7.6     dplyr_1.0.10      grid_4.2.2       
## [37] cli_3.3.0         tools_4.2.2       magrittr_2.0.3    sass_0.4.1       
## [41] lazyeval_0.2.2    tibble_3.1.7      crayon_1.5.1      tidyr_1.2.0      
## [45] pkgconfig_2.0.3   ellipsis_0.3.2    data.table_1.14.2 assertthat_0.2.1 
## [49] rmarkdown_2.14    httr_1.4.3        rstudioapi_0.13   R6_2.5.1         
## [53] compiler_4.2.2